/*
 * ActionEvent.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.events;

/**
 * Action Event.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class ActionEvent extends SwingEvent {

// Public Static Fields. -------------------------------------------------------

  /**
   * The shift event mask.
   */
  public static final long SHIFT_MASK = InputEvent.SHIFT_MASK;

  /**
   * The ctrl event mask.
   */
  public static final long CTRL_MASK = InputEvent.CTRL_MASK;

  /**
   * The meta event mask.
   */
  public static final long META_MASK = InputEvent.META_MASK;

  /**
   * The alt event mask.
   */
  public static final long ALT_MASK = InputEvent.ALT_MASK;

  /**
   * Action performed id.
   */
  public static final int ACTION_PERFORMED = 1001;

// Private Static Fields. ------------------------------------------------------

  private static final long serialVersionUID = -9179975678510253908L;

// Private Fields. -------------------------------------------------------------

  private String actionCommand;
  private long when;
  private int modifiers;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new ActionEvent object.
   *
   * @param source the source of the event
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public ActionEvent(Object source) {
    this(source, ACTION_PERFORMED, 0);
  }

  /**
   * Constructs new ActionEvent object.
   *
   * @param source the source of the event
   * @param modifiers the keyboard modifiers
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public ActionEvent(Object source, int modifiers) {
    this(source, ACTION_PERFORMED, modifiers);
  }

  /**
   * Constructs new ActionEvent object.
   *
   * @param source the source of the event
   * @param id the event id
   * @param modifiers the keyboard modifiers
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public ActionEvent(Object source, int id, int modifiers) {
    this(source, id, null, 0, modifiers);
  }

  /**
   * Constructs new ActionEvent object.
   *
   * @param source the source of the event
   * @param id the event id
   * @param actionCommand the command string for the action
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public ActionEvent(Object source, int id, String actionCommand) {
    this(source, id, actionCommand, 0, 0);
  }

  /**
   * Constructs new ActionEvent object.
   *
   * @param source the source of the event
   * @param id the event id
   * @param actionCommand the command string for the action
   * @param modifiers the keyboard modifiers
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public ActionEvent(Object source, int id, String actionCommand,
                     int modifiers) {
    this(source, id, actionCommand, 0, modifiers);
  }

  /**
   * Constructs new ActionEvent object.
   *
   * @param source the source of the event
   * @param id the event id
   * @param actionCommand the command string for the action
   * @param when the time the event occurred
   * @param modifiers the keyboard modifiers
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public ActionEvent(Object source, int id, String actionCommand, long when,
                     int modifiers) {
    super(source, id);
    this.actionCommand = actionCommand;
    this.when = when;
    this.modifiers = modifiers;
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Returns the command string associated with this action.
   *
   * @return the command string associated with this action
   */
  public String getActionCommand() {
    return actionCommand;
  }

  /**
   * Returns the timestamp of when this event occurred.
   *
   * @return the timestamp of when this event occurred
   */
  public long getWhen() {
    return when;
  }

  /**
   * Returns keyboard modifiers.
   *
   * @return keyboard modifiers
   */
  public int getModifiers() {
    return modifiers;
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  public String paramString() {
    String idString;
    if (id == ACTION_PERFORMED) {
      idString = "ACTION_PERFORMED,cmd=";
    } else {
      idString = "unknown type,cmd=";
    }
    return idString + getActionCommand() + ",when=" + getWhen() +
           ",modifiers=" + InputEvent.getModifiersText(getModifiers());
  }

}
